<template>
  <el-dialog
    title="编辑等级"
    :visible.sync="editDialogData.isShow"
    :before-close="labelHandleClose"
    width="480px"
    @closed="cancelLabel"
  >
    <div class="form-box">
      <el-form
        ref="editForm"
        :model="editForm"
        label-width="100px"
        @submit.native.prevent
      >
        <el-form-item label="编辑马甲等级:" prop="robotGrade">
          <el-select v-model="editForm.robotGrade" clearable>
            <el-option
              v-for="item in robGradeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="success" plain @click="editDialogData.isShow = false"
        >取 消</el-button
      >
      <el-button
        type="success"
        class="add-note"
        :loading="loading"
        @click="edit('editForm')"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { editGradeAPI } from '@/api/vestManagement/vestManage' // 接口
export default {
  props: ['editDialogData'],
  data() {
    return {
      loading: false,
      // 表单数据
      editForm: {
        robotGrade: ''
      },
      robGradeList: [{ dictLabel: '请选择', dictValue: '' }]
    }
  },
  mounted() {
    this.getStatusList()
    this.robotId = this.editDialogData.params.id
  },
  methods: {
    async getStatusList() {
      // 马甲等级
      let robGrade = await sysNormalDisable('robot_grade')
      this.robGradeList = this.robGradeList.concat(robGrade)
    },
    /* 确认提交 */
    edit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = false
          let obj = { ...this.editForm }
          // obj.bindId = this.id
          editGradeAPI(
            this.robotId,
            obj,
            (response) => {
              this.loading = false
              this.$emit('refresh')
              this.cancelLabel()
            },
            (response) => {
              this.loading = false
              this.$message({
                message: response.message,
                type: 'warning'
              })
            }
          )
        } else {
          return false
        }
      })
    },

    // 对话框关闭 清空数据
    cancelLabel() {
      this.loading = false
      this.editDialogData.isShow = false
      this.editDialogData.params.id = ''
    },
    labelHandleClose(done) {
      this.cancelLabel()
      done()
    }
  }
}
</script>
<style lang="less" scoped></style>
